package com.bitbank.smartdevice.adapter

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import com.bitbank.newarch.ui.mine.MineFragment
import com.bitbank.smartdevice.ui.home.HomeFramgent
import com.bitbank.smartdevice.ui.shop.ShopFragment
import android.view.ViewGroup



/**
 *  Date：2018/12/21
 *  Author：xulee
 *  Desc：
 */
class MainPagerAdapter(var manager: FragmentManager) : FragmentPagerAdapter(manager) {

    private var fragments: Array<Fragment> = listOf(HomeFramgent(), ShopFragment(), MineFragment()).toTypedArray()

    override fun getItem(p0: Int): Fragment = fragments[p0]

    override fun getCount(): Int = fragments.size

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val fragment = super.instantiateItem(container, position) as Fragment
        manager.beginTransaction().show(fragment).commit()
        return fragment
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        val fragment = fragments[position]
        manager.beginTransaction().hide(fragment).commit()
    }

}